use std::fs::File;
use std::io::Error;

fn get_name(name: &str) -> Result<&str, &str> {
    match name {
        "lin" => Ok("lin2"),
        _ => Err("failed")
    }
}

fn all_method() {
    let a = Some(3);
    if ! a.is_none() {
        println!("a is not None");
    }

    // as_ref
    let t = Some("hello");
    let s = t.as_ref().map(|x| x.len());
    println!("s is {:?}", s);
    println!("still can visit {:?}", t);

    // ok_or
    let o = t.ok_or(0);
    println!("o is {:?}", o);
}

fn test() -> Result<(), Error> {

    println!("name: {:?}", get_name("lin"));
    println!("name2: {:?}", get_name("lin2"));
    Ok(())
}

fn main() -> Result<(), Error> {
    println!("Hello, world!");
    let res = test();
    let f = File::open("hello.txt");
    println!("f is {:?}", f);
    all_method();
    res
}
